package com.wz.jiangsu.main.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @program: wz
 * @author: wangzhou
 * @create: 2024-07-09 16:41
 * @description:
 **/
public class TestThread {
    public static void main(String[] args) throws InterruptedException{
        final int threadSize = 1000;
        ThreadUnsafeExample example = new ThreadUnsafeExample();
        final CountDownLatch countDownLatch = new CountDownLatch(threadSize);
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < threadSize; i++) {
            executorService.execute(() -> {
                example.add();
                countDownLatch.countDown();
            });
//            example.add();
        }
        countDownLatch.await();
        executorService.shutdown();
        System.out.println(example.get());

        new Thread(() -> {
            System.out.println("today is Friday!");
        },"wz").start();
        List<String> list = new ArrayList<>();
        list.add("wz");
        ExecutorService executorService1 = Executors.newCachedThreadPool();
    }
}

class ThreadUnsafeExample {

    private int cnt = 0;

    public void add() {
        cnt++;
    }

    public int get() {
        return cnt;
    }
}
